package com.teach.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.Caching;
import org.springframework.stereotype.Service;

import com.teach.entity.NewsClass;
import com.teach.mapper.NewsClassMapper;
import com.teach.service.NewsClassService;

@Service
public class NewsClassServiceImpl implements NewsClassService {

	@Autowired
	private NewsClassMapper mapper;
	
	@Cacheable(value = "NewsClassService",key = "'listAll'")
	@Override
	public List<NewsClass> listAll() {
			return mapper.selectAll();
	}
	
	@Cacheable(value="NewsClassService",key="'get'+#newsClassId")
	@Override
	public NewsClass get(Integer newsClassId) {
		return mapper.selectByPrimaryKey(newsClassId);
	}

	@CacheEvict(value = "NewsClassService",key="'listAll'")
	@Override
	public void add(NewsClass newsClass) {
		mapper.insertSelective(newsClass);
		
	}


//	@Caching(evict = {
//			@CacheEvict(value="NewsClassService",key="'get'+#newsClass.newsClassId"),
//			@CacheEvict(value = "NewsClassService",key="'listAll'")
//	})
	@CacheEvict(value="NewsClassService",allEntries = true)
	@Override
	public void update(NewsClass newsClass) {
		mapper.updateByPrimaryKeySelective(newsClass);
	}

	@CacheEvict(value="NewsClassService",key="'get'+#newsClassId")
	@Override
	public void delete(Integer newsClassId) {
		mapper.deleteByPrimaryKey(newsClassId);
	}

}
